package com.atguigu.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.atguigu.base.BaseMapper;
import com.atguigu.base.BaseServiceImpl;
import com.atguigu.entity.Permission;
import com.atguigu.entity.Role;
import com.atguigu.helper.PermissionHelper;
import com.atguigu.mapper.PermissionMapper;
import com.atguigu.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @Author: 翟文海
 * @Date: 2022/11/4/004 13:13
 * @Version: 1.0
 * @Description:
 **/
@Service(interfaceClass = PermissionService.class)
public class PermissionServiceImpl extends BaseServiceImpl<Permission> implements PermissionService {
    @Autowired
    private PermissionMapper permissionMapper;

    @Override
    protected BaseMapper<Permission> getMapper() {
        return permissionMapper;
    }

    @Override
    public List<Permission> findMenu(Long adminId) {
        List<Permission> permissionList = null;
        if (adminId==1) {
            permissionList = permissionMapper.findAll();
        } else {
            permissionList = permissionMapper.findByAdminId(adminId);
        }
        //不是一级菜单的过滤掉
        return PermissionHelper.build(permissionList);
    }

    public List<Permission> findPermissionListByAdminId(Long adminId){
        if (adminId == 1) {
            return permissionMapper.findAll();
        }
       return permissionMapper.findByAdminId(adminId);
    }

}
